<?php

namespace app\api\exception;
use app\api\exception\Exception;
use think\exception\Handle;
use think\Response;
use Throwable;

class Handler extends Handle {

  public $httpStatus = 500;

  public function render($request, Throwable $e): Response {
    $status = $e->status ?? config('status.error');
    if (method_exists($e, 'getStatusCode')) {
      $httpStatus = $e->getStatusCode();
    } else {
      $httpStatus = $this->httpStatus;
    }
    if($e instanceof Exception) {
      $message = $e->getMessage();
    } else {
      $message = '服务器内部错误';
    }
    $message = $e->getMessage();
    return message($status, $message, null, $httpStatus);
  }

}